#region usingStatements
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using PHSRAG.Insight21.InsightWebControls;
#endregion

namespace PHSRAG.Insight21.ClinicalTrials.Controls
{
	/// <summary>
	///	Creates Budget Tabs Buttons which is used after the summary
	/// </summary>
	public partial class BudgetTabs : System.Web.UI.UserControl
	{
      #region Instance Variables
      private Budget budget;
      private enum PageNames
      {
         BudgetSetup = 0,
         BudgetStaffing,
         BudgetVisits,
         BudgetOtherCosts,
         BudgetSummary
      }
      #endregion

      #region Private Methods
      /// <summary>
      /// Runs upon Page.Load.  Setup all tabs
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      protected void OnPageLoad(object sender, System.EventArgs e)
		{
			budget = (Budget)((Policy.ICachePolicy)Session[Policy.Names.CachePolicyKey]).GetCachedObject( Budget.CacheKey );

			string path = Request.Path.Substring( Request.Path.LastIndexOf( "/" ) + 1 );
			path = path.Substring( 0, path.IndexOf( ".aspx" ));
		     
			switch (path)
			{
				case ("BudgetSetup"):
					setup.CssClass="BudgetTabsSelectedButton";
					staffing.CssClass="BudgetTabsButton";
					visits.CssClass="BudgetTabsButton";
					otherCosts.CssClass="BudgetTabsButton";
					summary.CssClass="BudgetTabsButton";
					break;
				case ("BudgetStaffing"):
					setup.CssClass="BudgetTabsButton";
					staffing.CssClass="BudgetTabsSelectedButton";
					visits.CssClass="BudgetTabsButton";
					otherCosts.CssClass="BudgetTabsButton";
					summary.CssClass="BudgetTabsButton";
					break;
				case ("BudgetVisits"):
					setup.CssClass="BudgetTabsButton";
					staffing.CssClass="BudgetTabsButton";
					visits.CssClass="BudgetTabsSelectedButton";
					otherCosts.CssClass="BudgetTabsButton";
					summary.CssClass="BudgetTabsButton";
					break;
				case ("BudgetOtherCosts"):
					setup.CssClass="BudgetTabsButton";
					staffing.CssClass="BudgetTabsButton";
					visits.CssClass="BudgetTabsButton";
					otherCosts.CssClass="BudgetTabsSelectedButton";
					summary.CssClass="BudgetTabsButton";
					break;
				case ("BudgetSummary"):
					setup.CssClass="BudgetTabsButton";
					staffing.CssClass="BudgetTabsButton";
					visits.CssClass="BudgetTabsButton";
					otherCosts.CssClass="BudgetTabsButton";
					summary.CssClass="BudgetTabsSelectedButton";
					break;
				}
		}
      #endregion
      
      #region Overrides
      /// <summary>
      /// Set the enabled property just before rendering because the conditions may change
      /// upon postback.
      /// </summary>
      /// <param name="e"></param>
      protected override void OnPreRender(EventArgs e)
      {		  
          // the budget must be created for tabs other than setup to be navigable.
          if (budget.Id == 0)
          {
              staffing.Enabled = false;
              visits.Enabled = false;
              otherCosts.Enabled = false;
              summary.Enabled = false;
          }
          // The Visits tab requires at least one saved BudgetStaff on the Budget
          else if (budget.BudgetStaff.Count == 0 || ((BudgetStaff)budget.BudgetStaff[0]).Id == 0)
          {
              staffing.Enabled = true;
              visits.Enabled = false;
              otherCosts.Enabled = true;
              summary.Enabled = true;
          }
          else
          {
              staffing.Enabled = true;
              visits.Enabled = true;
              otherCosts.Enabled = true;
              summary.Enabled = true;
          }
          base.OnPreRender (e);
      }
      #endregion
      
      #region Web Form Designer generated code
      /// <summary>
      /// Handler for the event raised when the page is being initialized.
      /// </summary>
      /// <param name="e"></param>
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.OnPageLoad);

		}
		#endregion

		protected void OnSetupSelected(object sender, System.EventArgs e)
		{			
			Response.Redirect("BudgetSetup.aspx");
		}

		protected void OnStaffingSelected(object sender, System.EventArgs e)
		{
			Response.Redirect("BudgetStaffing.aspx");
		}

		protected void OnVisitsSelected(object sender, System.EventArgs e)
		{
			Response.Redirect("BudgetVisits.aspx");
		}

		protected void OnOtherCostsSelected(object sender, System.EventArgs e)
		{
			Response.Redirect("BudgetOtherCosts.aspx");
		}

		protected void OnSummarySelected(object sender, System.EventArgs e)
		{
			Response.Redirect("BudgetSummary.aspx");
		}
	}
}